package com.topc.oj.result;

import cn.hutool.core.util.ObjectUtil;
import com.topc.base.utils.LogUtils;
import com.topc.oj.enums.CodeStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import static com.topc.oj.enums.CodeStatusEnum.*;

@Data
@Accessors(chain = true)
public class CodeFinalResult {

    private CodeStatusEnum codeStatusEnum;

    private String errorInfo;

    public CodeFinalResult() {
    }

    @Override
    public String toString() {
        return "CodeResult{" +
                "codeStatusEnum=" + codeStatusEnum +
                ", errorInfo='" + errorInfo + '\'' +
                '}';
    }

    public CodeFinalResult(CodeRunResult codeRunResult, String rightAnswer) {
        switch (codeRunResult.getCodeStatusEnum()) {
            case Finish:
                //盘梯部分
                String codeContent = codeRunResult.getContentInfo().replaceAll("\\s+", "");
                String rightContent = rightAnswer.replaceAll("\\s+", "");
//                String codeContent = codeRunResult.getContentInfo().replaceAll("\r","");
//                String rightContent = rightAnswer.replaceAll("\r","");
                LogUtils.getLog().info("运行结果内容 => ",codeContent);
                LogUtils.getLog().info("答案内容 => ",rightContent);
                LogUtils.getLog().info("比对中ing ------");
                LogUtils.getLog().info("编译答案:{}",codeContent);
                LogUtils.getLog().info("正确答案:{}",rightContent);
                System.out.println(codeContent.length()+"  "+rightAnswer.length());
                if (ObjectUtil.equal(codeContent, rightContent))
                    this.setCodeStatusEnum(Finish);
                else this.setCodeStatusEnum(CodeStatusEnum.WR);
                break;
            case MLE:
                this.setCodeStatusEnum(MLE);
                break;
            case TLE:
                this.setCodeStatusEnum(TLE);
                break;
            case ERROR:
                this.setCodeStatusEnum(CodeStatusEnum.ERROR);
                break;
            default:{
                this.setCodeStatusEnum(CodeStatusEnum.UN_KNOW);
            }
        }

    }
}
